package com.hlddz.venue_reservation.mapper;

import com.hlddz.venue_reservation.dto.ReserveDetailDto;
import com.hlddz.venue_reservation.entity.Reserve;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author MoShang
 * @since 2024年05月31日
 */
@Mapper
public interface ReserveMapper extends BaseMapper<Reserve> {

     @Insert("insert into reserve (username, venue_id, reserve_date, reserve_time, status, submit_time) values (#{username}, #{venueId}, #{reserveDate}, #{reserveTime}, #{status}, #{submitTime})")
     @Options(useGeneratedKeys = true, keyProperty = "reserveId")
     void doReserve(Reserve reserve) ;
     @Select("select * from reserve")
     List<Reserve> getReserves();

     @Select("SELECT reserve.reserve_id, reserve.username, reserve.venue_id, reserve.reserve_date, reserve.reserve_time, reserve.status, COUNT(*), venue.venue_name\n" +
             "        FROM reserve\n" +
             "                 JOIN reserve_visitor ON reserve.reserve_id = reserve_visitor.reserve_id\n" +
             "                 JOIN venue ON reserve.venue_id = venue.venue_id\n" +
             "        WHERE reserve.username = #{username}\n" +
             "        GROUP BY reserve.reserve_id")
     List<ReserveDetailDto> SelectReserveList(@Param("username") String username);

     @Update("update reserve set status=#{status} where reserve_id=#{reserveId}")
     void UpdateReserveStatus(@Param("reserveId")int reserveId,@Param("status")String status);
}
